package com.apes.scm.masterdata.frame.model;

import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.scm.masterdata.stock.model.Depot;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;

/**
 * 采购范围
 *
 * @author wuq
 * @create 2018-07-16 9:38
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = PurchaseRanges.CONST_TABLE_NAME, indexes = {
        @Index(columnList = "purchase_org_id, depot_id", unique = true)
})
public class PurchaseRanges extends Model {
    public static final String CONST_TABLE_NAME = "mas_purchase_ranges";

    @Id
    @Column(name = "id", length = 30)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "采购范围", prefix = "8")
    @Comment("编码")
    private String id;  //编码

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "purchase_org_id", referencedColumnName = "id")
    @Comment("采购组织编码")
    private Organization purchaseOrg;  //采购组织


    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "depot_id", referencedColumnName = "id")
    @Comment("仓库编码")
    private Depot depot;  //仓库

//    @Column(name = "valid", nullable = false, columnDefinition = "number(1,0) default 1")
//    private boolean valid = true; //有效

}
